package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Set;

import org.testng.annotations.Test;

public class GroupModificationTests extends TestBase {
	@Test
	public void testfirstGroupCanBeModified() throws Exception {

		Set<GroupObject> oldList = app.getGroupHelper().getGroups();
		GroupObject validGroup = new GroupObject().setFooter("asdasd")
				.setHeader("ads").setName("asdasd");
		GroupObject firstGroup = app.getGroupHelper().selectFirstGroup();
		app.getGroupHelper().modifyGroup(0, validGroup);
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		verifyGroupModified(oldList, validGroup,firstGroup, newList);
	}

	private void verifyGroupModified(Set<GroupObject> oldList,
			GroupObject validGroup, GroupObject firstGroup,Set<GroupObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size()));
		oldList.remove(firstGroup);
		validGroup.setId("$$$");
		oldList.add(validGroup);
		validGroup.setId(null);
		assertThat(newList, equalTo(oldList));
	}

}